/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.sys.service;

import com.thinkgem.jeesite.common.service.TreeService;
import com.thinkgem.jeesite.modules.sys.dao.CategoryDao;
import com.thinkgem.jeesite.modules.sys.entity.Category;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * 机构Service
 * @author ThinkGem
 * @version 2014-05-16
 */
@Service
@Transactional(readOnly = true)
public class CategoryService extends TreeService<CategoryDao, Category> {

	public List<Category> findAll(){
		return this.findList(true);
	}

	public List<Category> findList(Boolean isAll){
		Category category = new Category();
		return dao.findList(category);
	}
	
	@Transactional(readOnly = true)
	public List<Category> findList(Category category){
		if(category != null){
			category.setParentIds(category.getParentIds()+"%");
			return dao.findByParentIdsLike(category);
		}
		return  new ArrayList<Category>();
	}
	@Transactional(readOnly = true)
	public List<Category> findListByParentId(Category category){
		if(category != null){
			return dao.findByParentId(category);
		}
		return  new ArrayList<Category>();
	}
	@Transactional(readOnly = false)
	public void save(Category category) {
		super.save(category);
	}
	
	@Transactional(readOnly = false)
	public void delete(Category category) {
		super.delete(category);
	}
	
}
